using System.Collections.Generic;
using NBehave.Spec.MbUnit;
using Pentago.Core;

namespace Pentago.Specifications
{
    internal class GameBlockSetup
    {
        private readonly IGameBlock gameBlock;

        public GameBlockSetup()
        {
            gameBlock = new GameBlock(1);
        }

        public GameBlockSetup AddWhiteMarblesToLocations(params int[] locations)
        {
            return AddMarblesToLocations(locations, Marble.White);
        }

        public GameBlockSetup AddBlackMarblesToLocations(params int[] locations)
        {
            return AddMarblesToLocations(locations, Marble.Black);
        }

        private GameBlockSetup AddMarblesToLocations(IEnumerable<int> locations, Marble colour)
        {
            foreach (var location in locations)
                gameBlock.Place(location, colour);

            return this;
        }

        public IGameBlock Create()
        {
            return gameBlock;
        }

        public void ShouldContainTheSameMarblesAs(IGameBlock other)
        {
            foreach (var pair in other.RetrieveAllMarbleLocations())
                gameBlock.IsOccupiedBy(pair.Key, pair.Value).ShouldBeTrue();  // todo: {location, Marble} pair is everywhere - make value object
        }
    }
}